#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QToolBar>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

    QMenu* menu1 = new QMenu("文件");
    menuBar->addMenu(menu1);

    //工具栏需要手动创建，本身不会自动创建
    QToolBar* toolBar = new QToolBar();
    this->addToolBar(toolBar);

    QAction* action1 = new QAction("1");
    action1->setToolTip("点击去死");

    action1->setIcon(QIcon(":/cat.jpg"));
    toolBar->addAction(action1);

    menu1->addAction(action1);

    connect(action1, &QAction::triggered, this, &MainWindow::handle);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    MainWindow::close();
}

